$fileName="{{fileName}}"
$contentType="{{contentType}}"
$targetDir="{{targetDir}}"
$overWrite="{{overWrite}}"

# create folder if not exists.
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null

$path= -join($targetDir, "\", $fileName)

if ( (Test-Path $path) -and ($overWrite -eq "false") ) {
    Write-Host "file exists and overWrite is set false, skip."
    Exit
}

$fileContent=@"
{{fileContent}}
"@
if ($contentType -eq "Base64") {
  $fileContent=[Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($fileContent))
}

$fileContent | Out-File -FilePath $path
Write-Host "upload file success."

